<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/jsp/comm_css_include.jsp"%>
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>
<head>
<style type="text/css">
	*{
	  margin: 0px;
	  padding: 0px;
	  font-size: 12px;
	}
</style>
</head>
<body class="gray-bg">

<!-- 隱藏域 -->
<input type="hidden" value="${busiId}" id="busiId" name="busiId"/>
<input type="hidden" value="${unitCode}" id="unitCode" name="unitCode"/>
<input type="hidden" value="${iden}" id="iden" name="iden"/>
<!-- 隱藏域 -->

<div class="container creditbody">
	<div class="iboxtitle">
		<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;业务受理>按揭日报表登记</span>
		<a href="javascript:void(0)"></a>
	</div>
	<div class="buttonfixed">
      <button type="button" class="btn dpbtn_blue" onclick="allocation();" id="tjbiaobiao" name="tjbiaobiao">提交报表</button>
    </div>
	<div class="ibox-content ibox-con">
		<%@include file="/jsp/common_yw_with_loan_include.jsp"%>
		<div class="business-manwife">流程信息</div>
		<div class="business-padding">
			<div class="business-padding" id="">
				<table class="yw-course">
					  <thead>
					    <tr>
					        <th id="added_status1" equal="0"   class="splztab bg-green">按揭日报表</th>
					        <th id="dianzi" equal="30"  class="splztab">申请垫资</li>
		           			<th id="M_cwshy" equal="50"  class="splztab">财务审核1</th>
		           			<th id="M_cwshe" equal="200" class="splztab">财务审核2</th>
		           			<th id="caiwudiankuan" class="splztab">财务垫款</th>
		           			<th id="" class="splztab">垫款调整A</th>
		           			<th id="" class="splztab">申请垫款调整Ｂ</th>
		           			<th id="" class="splztab">垫款调整Ｂ审核</th>
		           			<th id="" class="splztab">垫款调整Ｂ</th>
		           			<th id="" class="splztab">财务退款</th>
					    </tr>
					  </thead>
				</table>
			</div>
		</div>
			
		<div class="business-manwife">垫款信息</div>
		 <form class="form-horizontal" id="commentForm">
           	<div class="padding-nono">
	        <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
			 <tr>
			 	<td align="right">
					<label class="control-label warn-red-bold">车辆类型：</label>
				</td>
				<td>
					<input  class="form-control" type="text" value="${car.carTypeDisplay}" readonly="readonly"/>
				</td>
			</tr>	
			<tr>	
				<td align="right">
					<label class="control-label np">收款人/单位：</label>
				</td>
				<td>
					<input  class="form-control" type="text" id="account_name_receiver" name="account_name_receiver" required="required" placeholder="收款人/单位(必填)" readonly="readonly"/>
				</td>
				<td align="right">
					<label class="control-label np">开户银行：</label>
				</td>
				<td>
					<input  class="form-control" type="text" id="name_bank_receiver" name="name_bank_receiver" required="required" placeholder="开户银行(必填)" readonly="readonly"/>
				</td>
			</tr>	
			<tr>
				<td align="right">
					<label class="control-label np">账号：</label>
				</td>
				<td>
					<input  class="form-control" type="text" id="accounn_no_receiver" name="accounn_no_receiver" required="required" placeholder="账号(必填)" readonly="readonly"/>
				</td>
				<td align="right">
					<label class="control-label np">结算方式：</label>
				</td>
				<td>
					<select  class="select-control" id="type_balance" name="type_balance" required="required"></select>
				</td>
			</tr>
			<tr>	
				<td align="right">
					<label class="control-label np">第一年投保：</label>
				</td>
				<td>
					<select  class="select-control" id="object_insure1" name="object_insure1">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
				<td align="right">
					<label class="control-label np">第一年收益：</label>
				</td>
				<td>
					<select  class="select-control" id="object_earnings1" name="object_earnings1">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
			</tr>
			<tr>	
				<td align="right">
					<label class="control-label np">第二年投保：</label>
				</td>
				<td>
					<select  class="select-control" id="object_insure2" name="object_insure2">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
				<td align="right">
					<label class="control-label np">第二年收益：</label>
				</td>
				<td>
					<select  class="select-control" id="object_earnings2" name="object_earnings2">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
			</tr>
			<tr>	
				<td align="right">
					<label class="control-label np">第三年投保：</label>
				</td>
				<td>
					<select  class="select-control" id="object_insure3" name="object_insure3">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
				
				<td align="right">
					<label class="control-label np">第三年收益：</label>
				</td>
				<td>
					<select  class="select-control" id="object_earnings3" name="object_earnings3">
						<option value="1">集团外部</option>
						<option value="2">集团内部</option>
					</select>
				</td>
			</tr>
		</table>
		
		<table cellpadding="0" cellspacing="0" border="0" class="thead-table padding-wanggeb">
			<thead class="thead-a">
				<tr>
					<th class="warn-red-bold">实际贷款额</th>
					<th class="warn-red-bold">签约贷款额</th>
					<th class="warn-red-bold">按揭服务费</th>
					<th class="warn-red-bold">征信押金</th>
				</tr>
			</thead>
			<tbody class="tbody-a">
				<tr>
					<td class="zxyjred">
						<input class="tbody-control" id="amount"  readonly="readonly"/>
					</td>
					<td class="zxyjred">
						<input class="tbody-control" id="sign_loan_amount"  readonly="readonly"/>
					</td>
					<td class="zxyjred">
						<input class="tbody-control" id="anjie_amount"  readonly="readonly"/>
					</td>
					<td class="zxyjred">
						<input class="tbody-control" id="valueExtras"   readonly="readonly"/>
					</td>
				</tr>
			</tbody>
		</table>
		
		<!-- 安街日报表 -->
		<table cellpadding="0" cellspacing="0" border="0" class="thead-table" style="margin-top: 0px;" id="serverMoney" name="serverMoney">
			<thead class="thead-a">
				<tr>
					<th>抵押费</th>
					<th>二手车评估费</th>
					<th>其他费用</th>
					<th class="zxyjred">续保押金</th>
					<th>开户费</th>
					<th>分期付款手续费</th>
					<th>上牌服务费</th>
				</tr>
			</thead>
			<tbody class="tbody-a">
				<tr>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="33" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="32" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="26" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td class="zxyjred"><input class="tbody-control" type="text" required="required"  name="dianName" id="25" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="24" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="23" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="22" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
				</tr>
			</tbody>
			<thead class="thead-a">
				<tr>
					<th>预收保费</th>
					<th>上牌保证金</th>
					<th>上门家访费</th>
					<th>安装GPS费</th>
					<th>咨询服务费</th>
					<th class="zxyjred">履约押金</th>
					<th>公证抵押费</th>
				</tr>
			</thead>
			<tbody class="tbody-a">
				<tr>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="21" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="08" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="07" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="06" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="05" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td class="zxyjred"><input class="tbody-control" type="text" required="required"  name="dianName" id="03" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
					<td><input class="tbody-control" type="text" required="required"  name="dianName" id="02" value="0" onkeyup="am(this);" onafterpaste="am(this);"/></td>
				</tr>
			</tbody>
			<thead class="thead-a">
				<tr>
					<th>合计</th>
				</tr>
			</thead>
			<tbody class="tbody-a">
				<tr>
					<td><input class="tbody-control" type="text"  readonly="readonly" id="heji" name="heji"></td>
				</tr>
			</tbody>
		</table>
	</div>
	<!-- //新增返利信息 ---chengliyong-->
	<div class="business-manwife">返利信息</div>
       <div class="padding-nono">
	    <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
			 <tr>
				<td align="right">
					<label class="control-label np">经销商返利：</label>
				</td>
				<td> 
					<input  class="form-control" type="number" id="rebate_dealer" name="rebate_dealer"  placeholder="经销商返利" />
				</td>	
				<td align="right">
					<label class="control-label np">分公司展业费：</label>
				</td>
				<td>
					<input  class="form-control" type="number" id="rebate_province" name="rebate_province" placeholder="分公司展业费" />
				</td>
			</tr>	
			<tr>
				<td align="right">
					<label class="control-label np">区域&业务员展业费：</label>
				</td>
				<td> 
					<input  class="form-control" type="number" id="rebate_area" name="rebate_area" placeholder="区域&业务员展业费" />
				</td>	
				<td align="right">
					<label class="control-label np">返利方式：</label>
				</td>
				<td>
					<select id="rebate_type" name="rebate_type" class="form-control">&nbsp;</select>
				</td>
			</tr>	
		</table>
	</div>
	</form>
	<div class="business-manwife">业务信息</div>
      <div class="business-padding">
		<table cellpadding="0" cellspacing="0" border="0" class="infor-table">
			 <tr>
				<td align="right">
					<label class="control-label np">业务来源人：</label>
				</td>
				<td>
					<div class="control-div np">${ywBusinessDetail.salesmanName }</div>
				</td>	
				<td align="right">
					<label class="control-label np">业务经办人：</label>
				</td>
				<td>
					<div class="control-div np">${current_user_key.uname }</div>
				</td>
				<td align="right">
					<label class="control-label np">业务办理时间：</label>
				</td>
				<td>
					<div class="control-div np"><fmt:formatDate value='${ywBusinessDetail.submitTime }' pattern='yyyy-MM-dd'/></div>
				</td>
			</tr>
		</table>
	</div>	
	<div class="business-manwife">经办信息</div>
       <div class="padding-nono">
	    <table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
			 <tr>
				<td align="right">
					<label class="control-label np">经办人：</label>
				</td>
				<td> 
					<input  class="form-control" type="text" id="uname" name="uname" placeholder="经办人" value="${current_user_key.uname}" readonly="readonly"/>
				</td>	
				<td align="right">
					<label class="control-label np">经办时间：</label>
				</td>
				<td>
					<input id="jb_time" name="jb_time" placeholder="经办时间" class="form-control" readonly="readonly"/>
				</td>
			</tr>	
		</table>
	</div>
</div>	
	<!-- public quote -->
    <%@include file="/jsp/comm_js_include.jsp"%>

    <!-- layerDate plugin javascript -->
    <script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>
    <!--
    	作者：zhangpp
    	时间：2017-04-06
    	描述：js
    -->
    <script type="text/javascript">
    
	    jQuery(function($) {
	    	var date = new Date();
	    	document.getElementById("jb_time").value = date.format("yyyy-MM-dd h:m:s");
	    	initData();
	    });
	    
	    $(function(){
	        $("#commentForm").validate({
	        	rules: {
	        		dianName:{
	            		 allMoney: true,
	            	},
	            	rebate_dealer:{
	            		 allMoney: true,
	            	}
	        	},
	            //重写showErrors
	            showErrors: function (errorMap, errorList) {
	                
	                $.each(errorList, function (i, v) {
	                    layer.tips(v.message, v.element, { time: 1500 });
	                    return false;
	                });  
	            },
	            /* 失去焦点时验证 */
	            onfocusout: function(element) { $(element).valid(); },
	            /*  键盘抬起不验证 */
	            onkeyup:false,
	        });
	    })
	    
	    var initData = function()
	    {
	    	//风控那边查询的时候 用到的
	    	var iden = $('#iden').val();
	    	if(iden && iden == "fksh")
	    	{
	    		$('.buttonfixed').hide();
	    	}
	    	
	    	var unitCode = $('#unitCode').val();
	    	var busiId = $('#busiId').val();
	    	
	    	$.dpAjax({
		   		url:'${basePath}/YwShouLiController/getAnJieDayBiao',
		   		data:{"unitCode":unitCode,"busiId":busiId},
				success: function(datas)
				{
			 	  if(datas.flag == "100100")
			 	  {
			 		  var objs = '';
			 		  
			 		  var d = datas.SettlementType_result;
			 		  for(var key in d)  
			 		  {
			 			  objs += '<option value="'+key+'">'+d[key]+'</option>';
			 		  }
			 		  $('#type_balance').html(objs);
			 		  
			 		  //返利方式
			 		  var d = datas.rebate_type;
			 		  if(d)
			 		  {
			 			  objs = "";
			 			  for(var key in d)
			 			  {
			 				 objs += '<option value="'+key+'">'+d[key]+'</option>';
			 			  }
			 			 $('#rebate_type').html(objs);
			 		  }
			 		  
			 		  var d = datas.remit;
			 		  if(d && null != d)
			 		  {
			 			$('#receiverId').val(d.replaceId);
			 			$('#account_name_receiver').val(d.accountName);
			 			$('#name_bank_receiver').val(d.bankId);
			 			$('#accounn_no_receiver').val(d.accounnNo);
			 		  }
			 		  
			 		  var d = datas.ywFees;
			 		  if(d && null != d)
			 		  {
			 			    $('#receiverId').val(d.replaceId);
				 			$('#account_name_receiver').val(d.accountNameReceiver);
				 			$('#name_bank_receiver').val(d.nameBankReceiver);
				 			$('#accounn_no_receiver').val(d.accounnNoReceiver);
				 			$('#rebate_dealer').val(d.rebateDealer);
				 			$('#rebate_province').val(d.rebateProvince);
				 			$('#rebate_area').val(d.rebateArea);
				 			
				 			var bk = document.getElementById("rebate_type");
							for(var i=0;i<bk.length;i++)
							{
								  if(d.rebateType == bk[i].value)
								  {
									  bk[i].selected = true;
									  break;
								  }
							}
							
							var bk = document.getElementById("type_balance");
							for(var i=0;i<bk.length;i++)
							{
								  if(d.typeBalance == bk[i].value)
								  {
									  bk[i].selected = true;
									  break;
								  }
							}
			 		  }
			 		  
			 		  var d = datas.ywFeesSub;
			 		  var value = 0;
			 		  for(var i=0;i<d.length;i++)
			 		  {
			 			  var pp =d[i];
			 			  var dianName = document.getElementsByName("dianName");
			 			  for(var x=0;x<dianName.length;x++)
			 			  {
			 				  if(dianName[x].id == pp['item_code'])
			 				  {
			 					 dianName[x].value = pp['amount_item'];
			 					 value += pp['amount_item'];
			 					 break;
			 				  }
			 			  }
			 		  }
			 		  
			 		  //征信押金
			 		  var ywBusinessExtras = datas.ywBusinessExtras;
			 		  if(ywBusinessExtras)
			 		  {
			 			  if(ywBusinessExtras.valueExtras)
			 			  {
			 				 $('#valueExtras').val(ywBusinessExtras.valueExtras);
			 			  }
			 			  else
			 			  {
			 				 $('#valueExtras').val("0.00");
			 			  }
			 		  }
			 		  else
			 		  {
			 			 $('#valueExtras').val("0.00");
			 		  }
			 		  
			 		  var business = datas.business;
			 		  if(business)
			 		  {
			 			 $('#sign_loan_amount').val((business.signLoanAmount));
				 		 $('#amount').val(business.realLoanAmount);
				 		 
				 		 /**
			 			 if(business.signLoanAmount && business.realLoanAmount)
			 			 {
			 				$('#anjie_amount').val(business.signLoanAmount - business.realLoanAmount);
			 			 }
				 		 **/
			 		  }
			 		  
			 		  var ywBusinessLoan = datas.ywBusinessLoan;
			 		  if(ywBusinessLoan)
			 		  {
			 			 $('#anjie_amount').val(ywBusinessLoan.servicePrice);
			 		  }
			 		  
 					 //合计增加征信押金、按揭服务费
 					  var valueExtras = parseFloat($('#valueExtras').val());
			 		  var servicePrice = parseFloat($('#anjie_amount').val());
			 		  var hejiNum = parseFloat(value+valueExtras+servicePrice);
			 		  $('#heji').val(hejiNum);
			 		  
			 		  //按揭日报表
			 		  var dictionary = datas.dictionary;
			 		  if(dictionary)
			 		  {
			 			  //按揭日报表
			 		  }
					  return;
				  }
				  layer.msg(datas.message, {icon: 2});
				}
		   	});
	    }
	    
	    //合计
	    var am = function(th)
	    {
	    	var b = th.value.indexOf(".");
	    	if(b < 0)
	    	{
	    		th.value = th.value;
	    	}
	    	
	    	//合计
	    	var dianName = document.getElementsByName("dianName");
	    	var value = 0;
	    	for(var i=0;i<dianName.length;i++)
	    	{
	    		var d = dianName[i];
	    		if(d.value != "")
	    		{
	    			value += parseFloat(d.value);
	    		}
	    	}
	    	//合计增加征信押金、按揭服务费
		    var valueExtras = parseFloat($('#valueExtras').val());
 		    var servicePrice = parseFloat($('#anjie_amount').val());
 		    var hejiNum = parseFloat(value+valueExtras+servicePrice);
	    	$('#heji').val(hejiNum);
	    }
	    
	    //保存提交
	    var allocation = function()
	    {
	    	var dianName = document.getElementsByName("dianName");
	    	var key = "";
	    	var value = "";
	    	for(var i=0;i<dianName.length;i++)
	    	{
	    		var d = dianName[i];
	    		
	    		key += d.id + ",";
	    		value += d.value + ",";
	    	}
	    	
	    	if(key != "" && value != "")
	    	{
	    		key = key.substring(0,key.length - 1);
	    		value = value.substring(0,value.length - 1);
	    		
	    		//拼接两个
	    		key += ",01,35";
	    		var anjie_amount = $('#anjie_amount').val();
	    		var valueExtras = $('#valueExtras').val();
	    		value += ","+anjie_amount+","+valueExtras;
	    	}
	    	
	    	var account_name_receiver = $('#account_name_receiver').val();
	    	var accounn_no_receiver = $('#accounn_no_receiver').val();
	    	var name_bank_receiver = $('#name_bank_receiver').val();
	    	var type_balance = $('#type_balance').val();
	    	var amount = $('#amount').val();
	    	var object_insure1 = $('#object_insure1').val();
	    	var object_earnings1 = $('#object_earnings1').val();
	    	var object_insure2 = $('#object_insure2').val();
	    	var object_earnings2 = $('#object_earnings2').val();
	    	var object_insure3 = $('#object_insure3').val();
	    	var object_earnings3 = $('#object_earnings3').val();
	    	var sign_loan_amount = $('#sign_loan_amount').val();
	    	var busiId = $('#busiId').val();
	    	var rebate_dealer = $("#rebate_dealer").val();
	    	var rebate_province = $('#rebate_province').val();
	    	var rebate_area = $('#rebate_area').val();
	    	var rebate_type = $('#rebate_type').val();
	    	var validstatus = $("#commentForm").valid();
	    	
	    	if(validstatus)
	    	{
	    		//询问框
		    	layer.confirm('按揭日报表提交就绪，是否执行？操作人：<span style="color:#BD1723;">${current_user_key.uname}</span>', {
		    	  btn: ['确定','取消'] //按钮
		    	}, function(){
		    		layer.closeAll();
		    		$.dpAjax({
		    	   		url:'${basePath}/YwShouLiController/ywShouLiAnJieDayBiaoBiao',
		    	   		data:{
		    	   			"busiId":busiId,
		    	   			"receiverId":$('#receiverId').val(), 
		    	   			"typeBalance":type_balance,
		    	   			"amount":amount,
		    	   			"objectInsure1":object_insure1,
		    	   			"objectEarnings1":object_earnings1,
		    	   			"objectInsure2":object_insure2,
		    	   			"objectEarnings2":object_earnings2,
		    	   			"objectInsure3":object_insure3,
		    	   			"objectEarnings3":object_earnings3,
		    	   			"signLoanAmount":sign_loan_amount,
		    	   			"accountNameReceiver":account_name_receiver,
		    	   			"accounnNoReceiver":accounn_no_receiver,
		    	   			"nameBankReceiver":name_bank_receiver,
				   			"addedStatus1":20,
				   			"key":key,
				   			"value":value,
				   			"rebateDealer":rebate_dealer,
				   			"rebateProvince":rebate_province,
				   			"rebateArea":rebate_area,
				   			"rebateType":rebate_type
		    	   		},
		    			success: function(datas){
		    		 	  if(datas.flag == "100100")
		    		 	  {
		    		 		  layer.msg("提交日报表成功！", {icon: 6});
		    		 		  setTimeout(function () {
		    		 			 window.location.href = "${basePath}/web/ywShouLi/applyLoaningDengjiList.jsp";
		    		 		  }, 3000);
		    				  return;
		    			  }
		    			  if(datas.flag == "100200"){
		    				  alert(JSON.stringify(datas));
		    	              return;
		    	          }
		    			  layer.msg(datas.message, {icon: 2});
		    			}
		    	   	});
		    		
		    	}, function(){
		    		 layer.msg('已取消本次操作！', {icon: 6});
		    	});
	    	 }else{
	    		 layer.msg('有验证未通过，请仔细检查！', {icon: 5});
	    	 }
	    }
    </script> 
</body>
</html>
